<template>
	<view class="Menu" :style="{ height: (windowHeight-$wanlshop.wanlsys().top) + 'px' }">
		<!-- 导航条 :style="{ height: $wanlshop.wanlsys().height + 'px' }"-->
		<view class="nav-Box" :style="{ top: $wanlshop.wanlsys().top + 'px'}">
			<view class="action"></view>
			<view class="content">
				<view class="tabs">
					<view class="tab" :class="{ active: activeIndex == 0 }" @click="changeTab(0)">
						{{$t('community.page.title1')}}
					</view>
					<view class="tab" :class="{ active: activeIndex == 1 }" @click="changeTab(1)">
						{{$t('community.page.title2')}}
					</view>
				</view>
			</view>
			<view class="action">
				<!-- <text class="wlIcon-gengduo" @tap="showModal('share')"></text> -->
			</view>
		</view>
		<!-- 内容 -->
		<view class="yqcode" v-if="activeIndex == 0" :style="{ height: (windowHeight-45) + 'px' }">
			<view class="codeContent" v-if="user&&user.isLogin">
				<image :src="shareObj.avatar" class="headImg" />
				<!-- <view class="name">{{ shareObj.nickname }}</view> -->
				<!-- <view class="tel">{{ shareObj.mobile }}</view> -->
				<view class="agent">{{ user.id }}</view>
				<view class="line"></view>
				<image :src="shareObj.image_url" class="eqImg" />
				<view class="copy">
					<!-- 邀请链接: -->
					{{$t('community.tips.yqlj')}}
					<view class="link">{{shareObj.url}}</view>
					<!-- <image src="@/static/images/index/copy.png" class="copyImg" @click="handleCopy(shareObj.url)" /> -->
				</view>
				<view class="share" @click="handleCopy(shareObj.url)">{{$t('community-but-share')}}<!-- 立即分享 --></view>
			</view>
		</view>
		<view class="mycommunity" :style="{ height: (windowHeight-45-$wanlshop.wanlsys().top) + 'px' }"
			v-if="activeIndex == 1">
			<view class="performance" v-if="obj&&user.isLogin">
				<view class="title">
					<!-- 累计业绩 -->
					<view class="agent">{{ shareObj.levelauth }}</view>
					<view class="rule" @click="findshow = true">
						<image src="@/static/images/index/question.png" />
						<!-- 成长规则 -->
						{{$t('community.tips.czgz')}}
					</view>
				</view>
				<view class="list">
					<view class="listImg">
						<image :src="obj.level_pic" mode="" class="images"></image>
						<!-- <image src="@/static/images/find/levelauth.png" mode="" class="images"></image> -->
						<!-- <view class="levelauth">{{obj.levelauth}}</view> -->
					</view>
					<view class="listRight">
						<view class="num" v-if="obj.sum_money">
							{{$t('community.tips.ljyj')}}: ${{obj.money }}
							<view class="total">/${{obj.sum_money}}</view>
							<!-- <view class="success">已完成</view> -->
						</view>
						<view class="line" v-if="obj.sum_money">
							<view class="linered" :style="{width:(obj.money/obj.sum_money)*100+'%'}"></view>
						</view>
						<view class="title">{{obj.leve_content}}</view>
					</view>
				</view>
			</view>
			<view class="heading" v-if="obj.recommend_data.mobile">{{$t('community.tips.wdyqr')}}<!-- 我的邀请人 --></view>
			<view class="recommendLowData" v-if="obj.recommend_data.mobile">
				<view class="performanceList">
					<view class="performanceLeft">
						<image :src="obj.recommend_data.avatar" class="headImg" />
						<view class="right">
							<view class="name">{{obj.recommend_data.nickname}}</view>
							<!-- <view class="tel">{{obj.recommend_data.mobile}}</view> -->
						</view>
					</view>
					<view class="agent">{{obj.recommend_data.levelauth}}</view>
				</view>
			</view>
			<view class="heading" style="font-weight: 400" v-if="obj.recommend_low_data.length>0">
				{{$t('community.tips.sqcy')}}<!-- 社区成员 -->
			</view>
			<view class="recommendLowData" v-if="obj.recommend_low_data.length>0">
				<view class="performanceList" v-for="(item,index) in obj.recommend_low_data" :key="index">
					<view class="performanceLeft">
						<image :src="item.avatar" class="headImg" />
						<view class="right">
							<view class="name">{{item.nickname ||'未填写'}}</view>
							<!-- <view class="tel">{{item.mobile}}</view> -->
						</view>
					</view>
					<view class="">
						<view class="agent">{{item.levelauth}}</view>
						<view class="tel">{{item.createtime}}</view>
					</view>
				</view>
			</view>
			<view class="fillbox" style="height: 120rpx;"></view>
		</view>
		<!-- 分享 -->
		<u-popup :show="findshow">
			<image class="buyimg" src="@/static/images/index/find.png" mode=""></image>
			<view class="cu-dialog" @tap.stop="">
				<image class="close" @click="handclose" src="@/static/images/index/close.png" mode=""></image>
				<view class="buybox">
					<view class="title">{{$t('community.tips.czgz')}} <!-- 成长规则 --></view>
					<view class="content" v-html="growthRules">
					</view>
					<view class="pays" @click="handclose"> {{$t('community.popup.but.confirm')}} <!-- 我知道了 --></view>
				</view>
			</view>
			<!-- #ifdef APP -->
			<view class="fillbox" style="height: 120rpx;"></view>
			<!-- #endif -->
		</u-popup>
		<view class="cu-modal bottom-modal" :class="modalName == 'share' ? 'show' : ''" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<wanl-shares :scrollAnimation="scrollAnimation" :shareTitle="goodsData.title"
					:shareText="goodsData.description" :image="$wanlshop.oss(goodsData.image, 50, 50)" :href="
            common.appConfig.domain +
            '/pages/newPage/setMenu?id=' +
            goodsData.id +
            '&QRtype=goods'
          " isReport @change="wanlShare" />
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from "vuex";

	export default {
		components: {},
		data() {
			return {
				windowHeight: 0,
				statusBar: 0,
				countdown: 3, // 修改广告倒计时
				cTimer: null,
				modalName: null, // 弹出层
				scrollAnimation: 100, //分享滚动
				goodsData: {
					title: "",
					description: "",
					id: "",
				},
				tabs: ["我的邀请码", "我的社区"],
				activeIndex: 0,
				findshow: false,
				obj: {
					recommend_low_data: [],
					recommend_data: [],
				},
				shareObj: "",
				growthRules: "",
			};
		},
		computed: {
			...mapState(["common", "user"]),
		},
		onLoad(options) {
			if (options && options.index) {
				this.activeIndex = options.index
			}
			var wanlsys = this.$wanlshop.wanlsys();
			this.windowHeight = wanlsys.windowHeight;

		},
		onShow() {
			let that = this
			let user = uni.getStorageSync("wanlshop:user")
			if (user) {
				this.handleDetail();
				this.getEqcode();
				this.getGrowthRules()
			} else {
				uni.showModal({
					title: "提示",
					content: "未登录,是否登录?",
					success(res) {
						if (res.confirm) {
							that.$wanlshop.to("/pages/user/auth/auth");
						} else {
							uni.switchTab({
								url: "/pages/index",
							});
						}
					}
				})
			}
		},
		methods: {
			changeTab(index) {
				if (!this.user.isLogin) {
					return uni.showToast({
						icon: 'none',
						title: "未登录,请先登录"
					})
				}
				let _self = this
				this.activeIndex = index
			},
			handleDetail() {
				uni.request({
					url: "/user/recommend",
					method: "POST",
					data: {},
					// 1.1.8 升级
					complete: (res) => {
						if (res.res.code == 1) {
							this.obj = res.res.data;
						}
					},
				});
			},
			getGrowthRules() {
				uni.request({
					url: "/index/upRule",
					method: "POST",
					data: {},
					complete: (res) => {
						if (res.res.code == 1) {
							this.growthRules = res.res.data
						}
					},
				});
			},
			getEqcode() {
				uni.request({
					url: "/user/buildQrcode",
					method: "POST",
					data: {},
					complete: (res) => {
						if (res.res.code == 1) {
							this.shareObj = res.res.data
						}
					},
				});
			},
			wanlShare(e) {
				if (e) {
					this.$wanlshop.auth(
						`/pages/user/complaint/complaint?id=${this.goodsData.id}&type=3`
					);
				} else {
					this.modalName = null;
				}
			},
			handclose() {
				this.findshow = false;
			},
			handleCopy(v) {
				uni.setClipboardData({
					data: v + "",
					success: () => {
						console.log(v);
					},
				});
			},
			// 弹出层
			showModal(name) {
				// 滚动下分享
				if (name == "share" && this.modalName != "share") {
					setTimeout(() => {
						this.scrollAnimation = 0;
					}, 300);
				}
				this.modalName = name;
			},
			// 关闭弹出层
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					this.modalName = null;
				}
			},
			loadExecution() {
				/**
				 * 获取本地存储中launchFlag的值
				 * 若存在，说明不是首次启动，直接进入首页；
				 * 若不存在，说明是首次启动，进入引导页；
				 */
				try {
					const value = uni.getStorageSync("wanlshop:launch");
					if (value || this.$store.state.common.adData.firstAdverts.length == 0) {
						if (value == true) {
							this.startTimer();
						} else {
							this.clearTimerGuide();
						}
					} else {
						uni.setStorage({
							key: "wanlshop:launch",
							data: true,
							success: (res) => {
								console.log("存储launchFlag");
							},
						});
						this.clearTimerGuide();
					}
				} catch (e) {
					// error
					uni.setStorage({
						key: "wanlshop:launch",
						data: true,
						success: (res) => {
							console.log("error时存储launchFlag");
						},
					});
					this.clearTimerGuide();
				}
				return;
				this.clearTimerIndex();
			},

			outBtn() {
				this.clearTimerIndex();
			},
			outImage() {
				this.clearTimerIndex();
			},
			handleShare() {},
			startTimer() {
				if (this.cTimer == null) {
					this.cTimer = setInterval(() => {
						this.countdown--;
						if (this.countdown == 0) {
							this.clearTimerIndex();
						}
					}, 1000);
				}
			},
			clearTimerIndex() {
				clearInterval(this.cTimer);
				this.cTimer = null;
				uni.switchTab({
					url: "/pages/index",
				});
			},
			clearTimerGuide() {
				uni.redirectTo({
					url: "/pages/guide",
				});
				clearInterval(this.cTimer);
				this.cTimer = null;
			},
		},
	};
</script>

<style lang="scss">
	.Menu {
		position: relative;
		background: #f8f8f8;

		.nav-Box {
			height: 45px;
			width: 100%;
			background-color: #ffffff;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.cardBox {
			padding: 0 24rpx;
		}

		.tabs {
			width: 100%;
			height: 68rpx;
			line-height: 68rpx;
			background: #f7f7f7;
			border-radius: 84rpx;
			display: flex;
			align-items: center;
		}

		.tabs .tab {
			flex: 1;
			padding: 0 20rpx;
			text-align: center;
			cursor: pointer;
			color: #666666;
		}

		.tabs .tab.active {
			width: 216rpx;
			height: 68rpx;
			background: #327CFF;
			border-radius: 40rpx;
			color: #fff;
		}

		.card {
			width: 100%;
			height: 294rpx;
			// background: url("../../static/images/index/gupiao.png") no-repeat;
			background-size: 100% 100%;
			margin-top: 40rpx;
			text-align: center;
			color: #fff;
			font-size: 28rpx;
		}

		.money {
			font-size: 60rpx;
			padding-top: 54rpx;
		}

		.all {
			margin-top: 10rpx;
		}

		.cardline {
			display: flex;
			justify-content: center;
			margin-top: 46rpx;
			align-items: center;

			.num {
				font-weight: 600;
				font-size: 40rpx;
				color: #ffffff;
			}
		}

		.details {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 24rpx;
			margin-top: 28rpx;
			color: #666666;

			.extract {
				padding: 10rpx 20rpx;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				border: 2rpx solid #327CFF;
				font-weight: 400;
				font-size: 28rpx;
				color: #327CFF;
			}
		}

		.listbox {
			background: #fff;
			padding: 0 24rpx;
			margin-top: 34rpx;

			// min-height:65vh;
			.list {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-top: 40rpx;
				padding-bottom: 40rpx;

				.listLeft {
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;

					.name {
						font-size: 28rpx;
						color: #333333;
						margin-top: 10rpx;
					}
				}

				.listRight {
					font-weight: 400;
					font-size: 32rpx;
					color: #327CFF;
				}
			}
		}

		.yqcode {
			width: 100%;
			height: 100vh;
			background: #fff;
			background-size: 100% 100%;

			.codeContent {
				width: 97%;
				margin: 0rpx auto;
				background: url(@/static/images/index/Subtract.png) no-repeat;
				background-size: 100% 100%;
				text-align: center;
				padding-bottom: 80rpx;
				position: relative;
				top: 10px;

				.headImg {
					width: 104rpx;
					height: 104rpx;
					border-radius: 50%;
					margin-top: 30rpx;
				}

				.name {
					font-size: 32rpx;
					color: #333333;
					margin-top: 20rpx;
				}

				.tel {
					font-size: 24rpx;
					color: #666666;
					margin-top: 10rpx;
				}

				.agent {
					width: 100rpx;
					height: 36rpx;
					line-height: 36rpx;
					background: #327CFF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-size: 24rpx;
					color: #fff;
					margin: 10rpx auto;
				}

				.line {
					width: 90%;
					margin-left: 5%;
					height: 1px;
					border-radius: 0rpx 0rpx 0rpx 0rpx;
					border: 2rpx dotted #d8d8d8;
					margin-top: 38rpx;
				}

				.eqImg {
					width: 324rpx;
					height: 324rpx;
					margin-top: 20rpx;
				}

				.copy {
					font-size: 28rpx;
					color: #666666;
					// display: flex;
					margin: 22rpx 30rpx;

					.link {
						word-wrap: break-word;
						word-break: break-all;
					}

					.copyImg {
						width: 32rpx;
						height: 32rpx;
						margin-left: 10rpx;
					}
				}

				.share {
					width: 590rpx;
					height: 96rpx;
					line-height: 96rpx;
					background: #327CFF;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					color: #fff;
					font-size: 28rpx;
					text-align: center;
					margin: 60rpx auto 0;
				}
			}
		}

		.mycommunity {
			background: #f8f8f8;
			width: 90%;
			margin-left: 5% !important;
			position: absolute;
			text-align: center;
			margin-top: 20rpx;

			.performance {
				width: 100%;
				padding: 28rpx 30rpx;
				background: #fff;
				border-radius: 16rpx;
			}

			.agent {
				width: 124rpx;
				height: 48rpx;
				background: #327CFF;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				color: #fff;
				line-height: 48rpx;
				text-align: center;
			}

			.recommendLowData {
				background: #f8f8f8;
				border-radius: 16rpx;
				width: 100%;
				margin-top: 30rpx;
			}

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;

				.rule {
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
					}

					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
				}
			}

			.list {
				display: flex;
				margin-top: 30rpx;

				.listImg {
					width: 140rpx;
					height: 140rpx;
					position: relative;
					display: flex;
					align-items: center;
					justify-content: center;

					.images {
						position: absolute;
						width: 140rpx;
						height: 140rpx;
					}

					.levelauth {
						position: relative;
						z-index: 1000;
						color: #ffffff;
					}
				}


				.listRight {
					margin-left: 20rpx;
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-around;

					.title {
						font-weight: 500;
						font-size: 24rpx;
						color: #666666;
					}

					.num {
						color: #FF443C;
						font-size: 24rpx;
						display: flex;
						position: relative;

						.total {
							color: #666666;
						}
					}

					.line {
						width: 100%;
						height: 16rpx;
						border-radius: 120rpx 120rpx 120rpx 120rpx;
						border: 1rpx solid #c1c1c1;
						overflow: hidden;
					}

					.success {
						width: 88rpx;
						height: 32rpx;
						background: #327CFF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						color: #fff;
						text-align: center;
						position: absolute;
						right: 0rpx;
						top: 20rpx;
					}

					.linered {
						background: #327CFF;
						height: 15rpx;
						border-radius: 120rpx 120rpx 120rpx 120rpx;
					}
				}
			}
		}

		.heading {
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
			margin-top: 20rpx;
		}

		.performanceList {
			background-color: #ffffff;
			margin-top: 20rpx;
			padding: 28rpx 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			border: 2rpx solid #E6E8EA;

			.performanceLeft {
				display: flex;
				align-items: center;
			}

			.headImg {
				width: 104rpx;
				height: 104rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			display: flex;
			justify-content: space-between;
			align-items: center;

			.tel {
				color: #666666;
				font-size: 24rpx;
				margin-top: 8rpx;
			}

			.name {
				color: #333;
				font-size: 28rpx;
			}

			.agent {
				width: 124rpx;
				height: 48rpx;
				background: #327CFF;
				border-radius: 100rpx;
				color: #fff;
				line-height: 48rpx;
				text-align: center;
				font-size: 24rpx;
			}
		}

		.buyimg {
			width: 238rpx;
			height: 238rpx;
			position: absolute;
			top: -110rpx;
			left: 36%;
			z-index: 9;
		}

		.close {
			width: 36rpx;
			height: 36rpx;
			position: absolute;
			right: 24rpx;
			top: 40rpx;
		}

		.pays {
			width: 90%;
			margin: 0 auto;
			height: 96rpx;
			background: #327CFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 36rpx;
			text-align: center;
			line-height: 96rpx;
			margin-top: 80rpx;
			margin-bottom: 50rpx;
		}

		/deep/ .u-popup__content {
			border-radius: 20rpx 20rpx 0 0;
		}

		.buybox {
			.title {
				font-size: 32rpx;
				text-align: center;
				font-weight: 500;
				padding-top: 130rpx;
			}

			.content {
				font-size: 28rpx;
				color: #666666;
				margin-top: 50rpx;
				height: 500rpx;
				overflow-y: scroll;
			}
		}
	}
</style>